export function formatTime(time) {
  // 获取时分秒
  let h = parseInt(time / 3600);
  let m = parseInt((time - h * 3600) / 60);
  let s = time - h * 3600 - m * 60;

  // 格式化
  m < 10 ? (m = `0${m}`) : "";
  s < 10 ? (s = `0${s}`) : "";

  if (h == 0) return `${m}:${s}`;

  h < 10 ? (h = `0${h}`) : "";
  return `${h}:${m}:${s}`;
}

export function getNowPage() {
  let pages = getCurrentPages();
  return pages ? pages[pages.length - 1] : null;
}

export function getThis() {
  let page = getNowPage();
  return page ? page.$vm : null;
}

/**
 * 数字转成汉字
 * @params num === 要转换的数字
 * @return 汉字
 * */
export function toChineseNum(num) {
  let changeNum = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
  let unit = ["", "十", "百", "千", "万"];
  num = parseInt(num);
  let getWan = (temp) => {
    let strArr = temp.toString().split("").reverse();
    let newNum = "";
    let newArr = [];
    strArr.forEach((item, index) => {
      newArr.unshift(
        item === "0" ? changeNum[item] : changeNum[item] + unit[index]
      );
    });
    let numArr = [];
    newArr.forEach((m, n) => {
      if (m !== "零") numArr.push(n);
    });
    if (newArr.length > 1) {
      newArr.forEach((m, n) => {
        if (newArr[newArr.length - 1] === "零") {
          if (n <= numArr[numArr.length - 1]) {
            newNum += m;
          }
        } else {
          newNum += m;
        }
      });
    } else {
      newNum = newArr[0];
    }

    return newNum;
  };
  let overWan = Math.floor(num / 10000);
  let noWan = num % 10000;
  if (noWan.toString().length < 4) {
    noWan = "0" + noWan;
  }
  return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
}
